<?php
class pageComponents extends sfComponents
{
  public function executeLanguages()
  {
    $languages = LanguagePeer::retrieveAll(new Criteria());
    
    //TODO fix language links from inner pages
    $routing = sfContext::getInstance()->getRouting();
    $uri = myTools::getCurrentInternalUri();
    
    foreach ($languages as $language)
    {
      if (preg_match('/@homepage?/', $uri))
      {
      	$uris[$language->getCulture()] = '@langhomepage?lang='.$language->getLang();
      	continue;
      }
      
      // if lang parameter is present
      if (preg_match('/lang=/', $uri))
      {
        $uris[$language->getCulture()] = eregi_replace('lang=[a-z]{2}', 'lang='.$language->getLang(), $uri);
      }
      else
      {
        $param = preg_match('/\?/', $uri) ? '&lang='.$language->getLang() : '?lang='.$language->getLang();
        $uris[$language->getCulture()] = $uri.$param;
      }
    }
    
    $this->languages = $languages;
    $this->uris = $uris;
  }  
}